//
//  ZFK_squareMainViewController.m
//  Drops
//
//  Created by SHG on 16/5/20.
//  Copyright © 2016年 Drops.er. All rights reserved.
//

#import "ZFK_squareMainViewController.h"
#import "AFNetworking.h"
#import "ZFK_header.h"
#import "ZFK_scrollPicView.h"
#import "ZFK_mainTableViewCell.h"

@interface ZFK_squareMainViewController ()

<
UITableViewDataSource,
UITableViewDelegate
>

@property (nonatomic, retain)NSMutableArray *scrollPicArray;    // 轮播图数组

@end

@implementation ZFK_squareMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createData];
    [self createMainTableView];
    [self createScrollPicView];
    
}

- (void)createData {
    [self getRequestWithString:@"http://www.fotoplace.cc/api/square/newIndex.do?lat=38.883491&lng=121.54447&city=0411&buildVersion=1&osNumber=1&clientVersion=3.2.1&seriesNumber=99000644068375&uid=25512642&token=e89ba406540046ccbfc816bb142cda852bc282b04bc844458cf9bf29899028b8" success:^(id jsonObject) {
        self.scrollPicArray = [NSMutableArray array];
        NSMutableArray *tempArr = jsonObject[@"data"][@"header"][@"activities"];
        [self.scrollPicArray addObject:tempArr.lastObject];
        
        for (NSInteger i = 0; i < tempArr.count; i++) {
            [self.scrollPicArray addObject:tempArr[i]];
        }
        
        [self.scrollPicArray addObject:tempArr.firstObject];
//        NSLog(@"count:%ld", self.scrollPicArray.count);
        [self createScrollPicView];         // 创建轮播图视图
    }];
}

- (void)createMainTableView {
    self.mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, sWIDTH, sHEIGHT) style:UITableViewStylePlain];
    self.mainTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainTableView];
    
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    
    [self.mainTableView registerClass:[ZFK_mainTableViewCell class] forCellReuseIdentifier:NSStringFromClass([ZFK_mainTableViewCell class])];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZFK_mainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZFK_mainTableViewCell class]) forIndexPath:indexPath];
    return cell;
}

- (void)createScrollPicView {
    ZFK_scrollPicView *scrollPicView = [[ZFK_scrollPicView alloc] initWithFrame:CGRectMake(0, 0, sWIDTH, sHEIGHT / 2 - sHEIGHT / 7)];
    scrollPicView.scrollPicArray = self.scrollPicArray;
    [self.mainTableView addSubview:scrollPicView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
